package com.zansc.longd.model.base.bean;

import com.zansc.longd.model.code.BaseCodeInterface;
import lombok.Data;

@Data
public class ResponseBean {
    
    // http 状态码
    private int code;
    
    // 返回信息
    private String msg;
    
    // 返回的数据
    private Object data;
    
    public ResponseBean() {
    
    }
    
    public ResponseBean(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    
    public static ResponseBean success(Object o) {
        ResponseBean responseBean = new ResponseBean();
        responseBean.setData(o);
        responseBean.setCode(200);
        responseBean.setMsg("成功");
        return responseBean;
    }
    
    public static ResponseBean success(String msg) {
        ResponseBean responseBean = new ResponseBean();
        responseBean.setData(null);
        responseBean.setCode(200);
        responseBean.setMsg(msg);
        return responseBean;
    }
    
    public static ResponseBean success(Object o, String msg) {
        ResponseBean responseBean = new ResponseBean();
        responseBean.setData(o);
        responseBean.setCode(200);
        responseBean.setMsg(msg);
        return responseBean;
    }
    
    public static ResponseBean success(int code, String msg) {
        ResponseBean responseBean = new ResponseBean();
        responseBean.setCode(code);
        responseBean.setMsg(msg);
        responseBean.setData(null);
        return responseBean;
    }
    
    public static ResponseBean success() {
        ResponseBean responseBean = new ResponseBean();
        responseBean.setData(null);
        responseBean.setCode(200);
        responseBean.setMsg("成功");
        return responseBean;
    }
    
    public static ResponseBean error(int code, String msg) {
        ResponseBean responseBean = new ResponseBean();
        responseBean.setCode(code);
        responseBean.setMsg(msg);
        responseBean.setData(null);
        return responseBean;
    }
    
    //删掉
    public static ResponseBean error(BaseCodeInterface e) {
        ResponseBean responseBean = new ResponseBean();
        responseBean.setCode(e.getResultCode());
        responseBean.setMsg(e.getResultMsg());
        responseBean.setData(null);
        return responseBean;
    }
    
}
